fix(frontend): gate credits API calls behind buyCredits feature flag - #646
fix(frontend): gate credits API calls behind buyCredits feature flag#646EmilFattakhov wants to merge 1 commit into
Conversation
The backend returns 404 for /credits/summary and /credits/batches/expiring when BUY_CREDITS_ACTIVE is disabled. SessionEnsurer was polling /credits/summary every 30 s and ExpiryWarningBanner was polling /credits/batches/expiring every 5 min for all authenticated users, flooding the console with 404 errors and adding unnecessary network overhead. Both queries now use `enabled: !!session?.data && !!features?.buyCredits` so they only fire when the feature flag is actually on. ExpiryWarningBanner also gains the useUserStore import needed to read the flag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for auto-drive-storage ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
| export const ExpiryWarningBanner = () => { | ||
| const { api } = useNetwork(); | ||
| const session = useContext(SessionContext); | ||
| const features = useUserStore((m) => m.features); |
There was a problem hiding this comment.
Stale persisted features can still cause 404 requests
Low Severity
ExpiryWarningBanner reads features from the Zustand store, which is persisted to localStorage and never cleared on logout (clearUser omits features). If buyCredits was previously true and the backend later disables the flag, the stale persisted value causes the query to fire on initial page load, producing the exact 404 this PR aims to prevent. SessionEnsurer avoids this by using the fresh useQuery result (which starts as undefined). The two components use inconsistent data sources for the same gating check.
Additional Locations (1)
|
Closing down as not needed |


The backend returns 404 for /credits/summary and /credits/batches/expiring when BUY_CREDITS_ACTIVE is disabled. SessionEnsurer was polling /credits/summary every 30 s and ExpiryWarningBanner was polling /credits/batches/expiring every 5 min for all authenticated users, flooding the console with 404 errors and adding unnecessary network overhead.
Both queries now use
enabled: !!session?.data && !!features?.buyCreditsso they only fire when the feature flag is actually on. ExpiryWarningBanner also gains the useUserStore import needed to read the flag.